<template>
  <div class="login_container">
    <!-- 登录表单盒子 -->
    <div class="login_box">
      <div class="avatar_box">
        <img src="../assets/logo.jpg" alt="">
      </div>
      <!-- 表单区域 -->
      <!-- 验证规则对象 表单数据对象两者中的属性名 必须一致-->
      <el-form ref="loginFormRef" :model="userInfo" :rules="loginFormRules" class="form_box" label-width="0px">
        <el-form-item prop="username">
          <el-input v-model="userInfo.username" prefix-icon="iconfont icon-user"></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input v-model="userInfo.password" type="password" prefix-icon="iconfont icon-3702mima"></el-input>
        </el-form-item>
        <el-form-item class="btns">
          <el-button type="primary" @click="login">登录</el-button>
          <el-button type="info">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { reactive, getCurrentInstance } from "vue";
import { useRouter } from "vue-router";
import loginComposition from "../composition/login/index.js";
export default {
  setup(props, context) {
    // 获取路由对象
    const router = useRouter();
    // 获取当前实例 用于访问挂载与全局的属性方法
    const { ctx } = getCurrentInstance();
    let { userInfo, loginFormRules, loginHandle } = loginComposition;
    const login = () => {
      loginHandle(ctx, router);
    };
    return {
      userInfo,
      loginFormRules,
      login
    };
  }
};
</script>

<style lang="less" scoped>
.login_container {
  background-color: #2b4b6b;
  height: 100%;

  .login_box {
    width: 450px;
    height: 300px;
    background-color: #fff;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);

    .avatar_box {
      width: 130px;
      height: 130px;
      border: 1px solid #eee;
      box-shadow: 0 0 10px #ddd;
      border-radius: 50%;
      padding: 10px;
      position: absolute;
      left: 50%;
      transform: translate(-50%, -50%);
      background-color: #fff;

      img {
        width: 100%;
        height: 100%;
        border-radius: 50%;
      }
    }

    .form_box {
      position: absolute;
      bottom: 0;
      width: 100%;
      padding: 0 20px;
      box-sizing: border-box;
    }

    .btns {
      display: flex;
      justify-content: flex-end;
    }
  }
}
</style>